//
//  ViewController.m
//  ImageTag_shootingMVDemo
//
//  Created by 高炀辉 on 2020/2/4.
//  Copyright © 2020 高炀辉. All rights reserved.
//

#import "ViewController.h"
#import <ZLPhotoBrowser/ZLPhotoBrowser.h>

@interface ViewController ()

@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[self imageWithText:@"趣活科技"]];
}
- (IBAction)shootingMV:(id)sender {
    // 拍摄视频
    // 直接调用相机
    ZLCustomCamera *camera = [[ZLCustomCamera alloc] init];
    // 最大录制时间
    camera.maxRecordDuration = 15;
    // 选择回调
    camera.doneBlock = ^(UIImage *image, NSURL *videoUrl) {
        // 自己需要在这个地方进行图片或者视频的保存
    };
    // 显示
    [self showDetailViewController:camera sender:nil];
}
- (UIImage *)imageWithText:(NSString *)text{
    /**
    这里之所以外面再放一个UIView，是因为直接用label画图的话，旋转就不起作用了
     */
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width/4.9, self.view.frame.size.width/4)];
    view.backgroundColor = [UIColor whiteColor];
    
    UILabel *label = [[UILabel alloc] initWithFrame:view.bounds];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor grayColor];
    label.text = text;
    label.transform = CGAffineTransformMakeRotation(-M_PI/4.0);
    [view addSubview:label];
    
    
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

@end
